#region "Copyright (C) Lenny Granovsky. 2011-2013"
//    This library provides extended cache capabilities to the ASP.NET applications.
//
//                Copyright (C) Lenny Granovsky. 2011-2013. 
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
//    This program comes with ABSOLUTELY NO WARRANTY.
//    This is free software, and you are welcome to redistribute it
//    under certain conditions;
#endregion

using System;

namespace FlexiCache
{
    /// <summary>
    /// Class contains information about CacheItem data stored in the out-of-process Cache.
    /// </summary>
    [Serializable]
    public class CacheItemInfo
    {
        /// <summary>
        /// Internal data identifier.
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// Binary data stored in the cache.
        /// </summary>
        public byte[] Item { get; set; }
        /// <summary>
        /// Item data length.
        /// </summary>
        public int DataLength { get; set; }

        /// <summary>
        /// Default constructor.
        /// </summary>
        public CacheItemInfo()
        {
            this.Id = "";
        }
    }

    /// <summary>
    /// Class contains data for storaging item in the out-of-process Cache.
    /// </summary>
    /// <remarks>This class should not be used within the application.</remarks>
    [Serializable]
    internal class CacheItem
    {
        private byte[] item;
        /// <summary>
        /// Internal data identifier.
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// Binary data stored in the cache.
        /// </summary>
        public byte[] Item
        {
            get
            {
                return item;
            }
            set
            {
                item = value;
                if (value != null)
                    DataLength = value.Length;
                else
                    DataLength = 0;
            }
        }
        /// <summary>
        /// Item expiration date and time.
        /// </summary>
        public DateTime Expiration { get; set; }
        /// <summary>
        /// Item data length.
        /// </summary>
        public int DataLength { get; set; }
        /// <summary>
        /// SessionId of the session associated with the data, if applicable. 
        /// This SessionId is in form of [AppId]+[ASP.NET Session Id].
        /// </summary>
        public string SessionId { get; set; }
        /// <summary>
        /// Gets or sets the metadata string associated with the cached data.
        /// </summary>
        public string Metadata { get; set; }

        /// <summary>
        /// Default constructor.
        /// </summary>
        public CacheItem()
        {
            this.Id = "";
            this.Expiration = DateTime.UtcNow;
            this.SessionId = "";
            this.Metadata = "";
        }
    }
}